<template>
  <div class="table-node" id="table-node" :style="[setCoordinate]">
    <div class="card">
      <!-- 表头 -->
      <div class="table-node-name">
        <span :style="{ color: `${node.color}` }"> {{ node.name }}</span>
      </div>
      <!-- 每一项 -->
      <div class=" card-item" @scroll="scrollevent">
        <div :id="`${node.name}`" class="table-node-fields">
          <!-- 表名和字段名拼接后用于绑定id与key确定节点（绘制节点和连线时用到，参见） 请保证两者的组合唯一 -->
          <div v-for=" field  in  node.fields " :key="`${node.name} - ${field.name}`" class="field">
            <img :src="`${datasrc[node.imageSrc]}`" style="width: 30px; height: 20px; ;" />
            <span class="spanitem" style="minWidth:30px; padding: 0px 5px;" :id="`${node.name}-${field.name}`">{{
              field.name }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

export default {
  name: "TableNode",//表节点组件
  props: {
    node: Object,
  },
  data() {
    return {
      datasrc: {
        image1: require('../../icon/yewuxitong.png'),
        image2: require("../../icon/shujuxitong.png"),
        image3: require("../../icon/yingyongxitong.png"),
        image4: require("../../icon/xinyongka.png"),
        image5: require('../../icon/fenhang.png')
      }
    }
  },
  methods: {
    sing() {
      alert('000')
    },
    scrollevent() {
      this.$emit('scrollevent')
    }
  },
  computed: {
    setCoordinate: {
      get() {
        return {
          top: this.node.top + "px",
          left: this.node.left + "px",
        };
      },
    }
  },
};
</script>

<style lang="less" scoped>
.table-node {
  position: absolute;
  cursor: move;
  align-items: center;
  background-image: url('../../icon/bg-zhong.png');
  background-color: "transparent";
  max-height: 400px;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  perspective: 800px;
  padding: 30px 0;
  width: 200px;

  .table-node-name {
    position: sticky;
    top: 30px;
    margin-bottom: 10px;
    background-color: "transparent";
    font-size: 18px;
  }

  .card {
    transform: rotateY(-35deg);
  }

  //每项数据
  .table-node-fields {
    align-items: center;
    max-width: 180px;
    margin-left: 30px;

    .field {
      min-width: 30px;
      display: flex;
      transform: scale(.9);
      font-family: verdana, sans serif;
      font-size: 14px;
      overflow: hidden;
      text-overflow: ellipsis;
      margin-bottom: 10px;
      align-items: center;
    }
  }
}

.card-item {
  display: flex;
  max-height: 340px;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  perspective: 800px;
  overflow: scroll;
}

.table-node::-webkit-scrollbar {
  display: none;
}

.card::-webkit-scrollbar {
  display: none;
}

.card-item::-webkit-scrollbar {
  display: none;
}
</style>
